//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//


//Our includes
#include "plQString.h"
#include "plDatabase.h"
#include "plData.h"

//////////////////////////////////////////////// Public ////////////////////////////////////////////////////

//Constructor
plQString::plQString() : plData() {
	Cached = false;
}

//Constructor
plQString::plQString(const char* value) : plData(){
	Value = QString(value);
	Disabled = true;
}

//Constructor
plQString::plQString(const QString& value) : plData() {
	Value = value;
	Disabled = true;
}

//Copy Constructor
plQString::plQString(const plQString& obj)  : plData(obj) {
	Copy(obj);
}

//Accessor
const QString& plQString::Data() const{
        plData::GetData();
	return Value;
}

//Modifier
void plQString::SetData(const QString& value) {
	Value = value;
        plData::SetData();
}

	
//Operator overloading
void plQString::operator=(const QString& value) {
	SetData(value);
}

//Operator overloading
void plQString::operator=(const plQString& obj) {
	Copy(obj);
}

//Operator overloading
void plQString::operator=(const char* value) {
	SetData(value);
}

plQString::operator const QString&() const {
	return Data();
}

plQString::operator QString() const {
	return Data();
}

//Binds the data with the statement
void plQString::Bind(sqlite3_stmt* statement, int index) const {
	sqlite3_bind_text16(statement, index, Value.data(), -1, SQLITE_STATIC);
}

//Gets the data from the current statement
void plQString::Column(sqlite3_stmt* statement, int index) {
	const unsigned short * text = (const unsigned short *)sqlite3_column_text16(statement, index);
	Value = QString::fromUtf16(text);
}

//Does a smart copy of the object
void plQString::Copy(const plQString& obj) {
	SetData(obj.Value);
}

